/*
 * Alloy Analyzer
 * Copyright (c) 2002 Massachusetts Institute of Technology
 *
 * The Alloy Analyzer is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The Alloy Analyzer is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the Alloy Analyzer; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package alloy.api;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;

/*
It is important that the tuples iterator be deterministic so that
the atoms of a type are numbered in order. Otherwise, symmetry
breaking will not give the atom names expected. For orderings, 
for example, we want the first atom in the ordering to correspond
the first atom by name.
*/

/** Represents one {@link Relation} */
public class Relation {
    private Set _tuples = new LinkedHashSet();

    public Relation() {
    }

    public void add(Tuple tuple_) {
        _tuples.add(tuple_);
    }

    public Iterator tuples() {
        return _tuples.iterator();
    }
    
    public int numberOfTuples() {
    	return _tuples.size();
    }

    public String toString() {
        String result = "\t{";
        for (Iterator iter = _tuples.iterator(); iter.hasNext();) {
            Tuple tuple = (Tuple)iter.next();
            result = result + "\n\t" + tuple.toString();
        }
        result += "\n\t}";
        return result;
    }
}
